package com.itheima.service.db.impl;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.itheima.domain.db.User;
import com.itheima.mapper.UserMapper;
import com.itheima.service.db.UserService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

@DubboService//暴露服务
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public Long save(User user) {
        //完善用户数据
        user.setPassword(SecureUtil.md5(user.getPassword()));//md5加密
//        user.setCreated(new Date());
//        user.setUpdated(new Date());

        userMapper.insert(user);
        return user.getId();
    }

    @Override
    public User findByMobile(String mobile) {
//        LambdaQueryWrapper<User> qw = new LambdaQueryWrapper<User>();
//        qw.eq(User::getMobile,mobile);//where mobile = "123123"
        QueryWrapper<User> qw = new QueryWrapper<>();
        qw.eq("mobile",mobile);


        return userMapper.selectOne(qw);
    }
}
